#!/usr/bin/python
# -*- coding: UTF-8 -*-

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer
from sqlalchemy.orm import sessionmaker, relationship


engine = create_engine('mysql+mysqldb://root:@127.0.0.1/stock?charset=utf8')
Base = declarative_base()

# Session = sessionmaker(bind=engine)
# session = Session()


class User(Base):

    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)
    username = Column(String(64), nullable=False, index=True)
    password = Column(String(64), nullable=False)
    email = Column(String(64), nullable=False, index=True)


    def __repr__(self):
        return '%s(%r)' % (self.__class__.__name__, self.username)

if __name__ == '__main__':
    Base.metadata.create_all(engine)

    Session = sessionmaker(bind=engine)
    session = Session()

    initalUser=User(
        username="zhangyi",
        password="study stock",
        email="123@123.com"
    ) 
    session.add(initalUser)

    session.commit()